package thread;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-05-11
 * Time：14:39
 */
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("main begin");

        Thread t1 = new Thread(() -> {
            System.out.println("t1 begin");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1 end");
        });
        t1.start();

        Thread t2 = new Thread(() -> {
            System.out.println("t2 begin");
            //等待t1结束
            try {
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2 end");
        });
        t2.start();

        //等待t2结束
        t2.join();
        System.out.println("main end");
    }
}
